package concurrent;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

public class Test {
	
	public static void main(String[] args) {
		MyContainer container = new MyContainer();
		
		Runnable t1 = new Runnable() {
			public void run() {
				for(int i=0; i<10; i++) {
					Object obj = new Object();
					container.add(obj);
					/*try {
						TimeUnit.SECONDS.sleep(1);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}*/
				}
			}
		};
		Runnable t2 = new Runnable() {
			public void run() {
				while (true) {
					if(container.size() == 5) {
						System.out.println("77777777");
						break;
					}
				}
			}
		};
		
		new Thread(t2).start();
		new Thread(t1).start();
		
		
	}
	
	
}

class MyContainer {
	volatile List<Object> mylist = new ArrayList<Object>();
	
	void add(Object obj) {
		mylist.add(obj);
	}
	
	int size() {
		return mylist.size();
	}
}
